import {
  Controller,
  Post,
  Body,
  Param,
  Delete,
  Req,
  Inject,
} from '@nestjs/common';
import { ArticleLikeService } from './article-like.service';
import { CreateArticleLikeDto } from './dto/create-article-like.dto';
import { LogAction } from 'src/auth/utils/logging.metadata';
import { PrismaService } from 'src/prisma.service';

@Controller('article-like')
export class ArticleLikeController {
  constructor(private readonly articleLikeService: ArticleLikeService) {}

  @Inject()
  prismaService: PrismaService;

  @LogAction('点赞文章')
  @Post()
  create(
    @Body() createArticleLikeDto: CreateArticleLikeDto,
    @Req() req: AuthRequest,
  ) {
    return this.articleLikeService.create(
      createArticleLikeDto,
      req.user.userId,
    );
  }

  // @Get()
  // findAll() {
  //   return this.articleLikeService.findAll();
  // }

  // @Get(':id')
  // findOne(@Param('id') id: string) {
  //   return this.articleLikeService.findOne(+id);
  // }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateArticleLikeDto: UpdateArticleLikeDto) {
  //   return this.articleLikeService.update(+id, updateArticleLikeDto);
  // }

  @LogAction('取消点赞文章')
  @Delete(':id')
  remove(@Param('id') id: string, @Req() req: AuthRequest) {
    return this.prismaService.articleLike.deleteMany({
      where: {
        articleId: parseInt(id),
        userId: req.user.userId,
      },
    });
  }
}
